<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>渠道核查</title>

        <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
        <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/common/jquery.global.settings.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
        <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
        <div class="easyui-container-fluid">
            <div class="easyui-panel" style="border: none;">
                <div class="nav" id="nav"></div>
                <div class="easyui-panel" style="border:none;">
                    <form id="ff" method="post">
                        <div style="margin-bottom: 20px;">
                            <label class="item-label">年：</label>
                            <input type="text" id="year" name="year" class="easyui-combobox" data-options="required:true" required="required" style="width: 100px;"/>
                            <span id="monthLabel">
                        <label class="item-label">月：</label>
                        <input type="text" id="month" name="month" class="easyui-combobox" data-options="required:true" required="required" style="width: 100px;">
                        </span>
                            <span id="weekLabel">
                        <label class="item-label">周：</label>
                        <input type="text" id="week" name="week" class="easyui-combobox" data-options="required:true" required="required" style="width: 100px;">
                            </span>
                            <a href="javascript:void(0);" class="easyui-linkbutton c8" onclick="searchBy()" style="width:80px;margin-left: 40px;">查询</a>
                        </div>
                    </form>
                </div>
                <div class="table-wrapper">
                    <table id="datagrid" class="easyui-datagrid" data-options="fitColumns:true,scrollbarSize:0">
                        <thead>
                        <tr>
                            <th data-options="field:'channelName',align:'center'" width="80">渠道</th>
                            <th data-options="field:'count',align:'center'" width="100" >本月（周）量</th>
                            <th data-options="field:'1',align:'center'" width="100" formatter="formatCount_0">-1月（周）量</th>
                            <th data-options="field:'2',align:'center'" width="100" formatter="formatCount_1">-2月（周）量</th>
                            <th data-options="field:'3',align:'center'" width="100" formatter="formatCount_2">-3月（周）量</th>
                            <th data-options="field:'4',align:'center'" width="100" formatter="formatCount_3">-4月（周）量</th>
                            <th data-options="field:'total',align:'center'" width="100" formatter="formatTotal" >本月（周）额</th>
                            <th data-options="field:'6',align:'center'" width="100" formatter="formatTotal_0">-1月（周）额</th>
                            <th data-options="field:'7',align:'center'" width="100" formatter="formatTotal_1">-2月（周）额</th>
                            <th data-options="field:'8',align:'center'" width="100" formatter="formatTotal_2">-3月（周）额</th>
                            <th data-options="field:'9',align:'center'" width="100" formatter="formatTotal_3">-4月（周）额</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </body>
    <script>
        $(function () {
            setNav();
            $("#datagrid").datagrid({
                pagination: true,
                rownumbers: true,
                checkOnSelect: false
            }).datagrid("getPager").pagination({
                onSelectPage: searchBy
            });
            $.when(initMonthWeek("monthLabel", "weekLabel"));
        });

        function searchBy() {
            var data = getFormData(document.getElementById("ff"));
            data.reportType=window.parent.workMode.toUpperCase();
            $.ajax({
                url:config.url + "/channelCheck/data",
                type:"GET",
                data:transfer(data),

                dataType:'json',
                xhrFields:{withCredentials:true},
                beforeSend:function () {
                    $.messager.progress({
                        title:"请稍等",
                        interval:50,
                        text:"数据加载中..."
                    });
                },
                success:function(data){
                    // console.log(Object.keys(data))
                    if(null != data &&data.length>0 ){
                        $.messager.progress("close");
                        $("#datagrid").datagrid({data: data}).datagrid("getPager");
                    }else {
                        $("#datagrid").datagrid({data: []}).datagrid("getPager");
                        $.messager.progress("close");
                    }
                },
                error:function(data){
                    console.log(data);
                    $.messager.progress("close");
                }
            });
        }

        function formatCount_0(val, row) {
            return row.allCount[0];
        }
        function formatCount_1(val, row) {
            return row.allCount[1];
        }
        function formatCount_2(val, row) {
            return row.allCount[2];
        }
        function formatCount_3(val, row) {
            return row.allCount[3];
        }
        function formatTotal_0(val, row) {
            return changeMoney(row.allTotal[0]);
        }
        function formatTotal_1(val, row) {
            return changeMoney(row.allTotal[1]);
        }
        function formatTotal_2(val, row) {
            return changeMoney(row.allTotal[2]);
        }
        function formatTotal_3(val, row) {
            return changeMoney(row.allTotal[3]);
        }
        function formatTotal(total) {
            return changeMoney(total);
        }
        function changeMoney(num) {
            var regexp = /(?:\.0*|(\.\d+?)0+)$/
            if (num > 1000000) {
                num = JSON.stringify(num).slice(0, JSON.stringify(num).length - 4) / 100
                return num + '万'
            } else {
                num = (num / 100).toFixed(2)
                num = num.replace(regexp, '$1')
                return num
            }
        }
    </script>
</html>